package com.lanou.service.Impl;

import com.lanou.entity.Tag;
import com.lanou.mapper.TagMapper;
import com.lanou.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @ClassName TagServiceImpl
 * @Description TODO
 * @Author chenzhaobao
 * @Date 2025年08月13日 11:14
 * @Version 1.0
 */
@Service
public class TagServiceImpl implements TagService {

    @Autowired
    private TagMapper tagMapper;

    @Override
    public int addTag(Tag tag) {
        return tagMapper.insertTag(tag);
    }

    @Transactional
    @Override
    public int deleteTagById(Integer id) {
        // 实际应用中应该先删除关联关系，再删除标签
        return tagMapper.deleteTagById(id);
    }

    @Transactional
    @Override
    public int deleteTagsByIds(List<Integer> ids) {
        // 实际应用中应该先删除关联关系，再删除标签
        int count = 0;
        for (Integer id : ids) {
            count += tagMapper.deleteTagById(id);
        }
        return count;
    }

    @Override
    public int updateTag(Tag tag) {
        return tagMapper.updateTag(tag);
    }

    @Override
    public Tag getTagById(Integer id) {
        return tagMapper.selectTagById(id);
    }

    @Override
    public List<Tag> getAllTags() {
        return tagMapper.selectAllTags();
    }

    @Override
    public List<Tag> getTagsByConsultantId(Integer consultantId) {
        return tagMapper.selectTagsByConsultantId(consultantId);
    }
}